-include_lib("ect/include/ect.hrl").
-module(tuser).
-import_class(gamma).
-import_class(alpha).
-import_class(beta).
-export([test_alpha/2, test_abeta/2, test_scall/2, test_new/2]).

test_alpha(1, _) ->
    A1 = #alpha{pub1 = pubi},
    A2 = {A1}:set(a, aaa),
    A3 = {A2}:set(b, bbb),
    A4 = {A3}:set(c, ccc),
    {aaa, bbb, pubi, ccc} = {A4}:get_all(),
    A5 = A4#alpha{pub1 = pubika},
    {aaa, bbb, pubika, ccc} = {A5}:get_all(),
    A5;
test_alpha(2, A1) ->
    {upgraded, {aaa, bbb, ccc}, pubika} = {A1}:get_all_v2(),
    pubika = A1#alpha.pub1,
    A2 = A1#alpha{pub1 = zed},
    zed = A2#alpha.pub1,
    ok.

test_abeta(1, _) ->
    A1 = #beta{pub1 = pubi},
    A2 = {A1}:set(a, aaa),
    A3 = {A2}:set(b, bbb),
    A4 = {A3}:set(c, ccc),
    {aaa, bbb, pubi, ccc} = {A4}:get_all(),
    A5 = A4#beta{pub1 = pubika},
    {aaa, bbb, pubika, ccc} = {A5}:get_all(),
    A5;
test_abeta(2, A1) ->
    {upgraded, {aaa, bbb, ccc}, pubika} = {A1}:get_all_v2(),
    pubika = A1#beta.pub1,
    
    Upgraded = {A1}:nottin(),
    New = #beta{},
    original = New#beta.bpub,
    upgraded = Upgraded#beta.bpub,
    
    A2 = A1#beta{pub1 = zed},
    zed = A2#beta.pub1,
    ok.

test_scall(1,_) ->
    A = #alpha{},
    B = #beta{},
    {beta,v1} = {B}:alpha_version(),
    v1 = {A}:alpha_version(),
    {A, B};
test_scall(2,{A,B}) ->
    {beta,v2} = {B}:alpha_version(),
    v2 = {A}:alpha_version(),
    
    A2 = #alpha{},
    B2 = #beta{},
    {beta,v2} = {B2}:alpha_version(),
    v2 = {A2}:alpha_version(),
    
    ok.

test_new(1, _) ->
    #alpha{flag = okay} =
        {_, {alpha, _, _,  _, _, _, _, _}} = #alpha{},
    #alpha{flag = okay} = #beta{flag = okay, bpub = original} =
        {_, {alpha, _, _,  _, _, _, _, _}, {beta, _, _,  _}} = #beta{},
    #alpha{flag = okay} = #gamma{flag = okay, y = asdf} =
        {_, {alpha, _, _,  _, _, _, _, _}, {gamma, _, _,  _, _, _}} = #gamma{},
    ok;
test_new(2, ok) ->
    #alpha{flag = okay} =
        {_, {alpha, _, _,  _, _, _, _}} = #alpha{},
    #alpha{flag = okay} = #beta{flag = okay, bpub = original} =
        {_, {alpha, _, _,  _, _, _, _}, {beta, _, _,  _}} = #beta{},
    #alpha{flag = okay} = #gamma{flag = okay, y = asdf} =
        {_, {alpha, _, _,  _, _, _, _}, {gamma, _, _,  _, _, _}} = #gamma{},
    ok.